xen/arm: Allow ballooning working with 1:1 memory mapping
authorJulien Grall <julien.grall@linaro.org>
Tue, 17 Dec 2013 14:28:19 +0000 (14:28 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 7 Jan 2014 13:31:19 +0000 (13:31 +0000)
With the lack of iommu, dom0 must have a 1:1 memory mapping for all
these guest physical address. When the balloon decides to give back a
page to the kernel, this page must have the same address as previously.
Otherwise, we will loose the 1:1 mapping and will break DMA-capable
devices.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
xen/arch/arm/domain_build.c
xen/common/memory.c
xen/include/asm-arm/domain.h

index faff88e8bc234de5fe2be36148139cbdb761cbe6..47b781b4206fa0bc5946835b758fe66861274115 100644 (file)
@@ -22,7 +22,7 @@
 static unsigned int __initdata opt_dom0_max_vcpus;
 integer_param("dom0_max_vcpus", opt_dom0_max_vcpus);
 
-static int dom0_11_mapping = 1;
+int dom0_11_mapping = 1;
 
 #define DOM0_MEM_DEFAULT 0x8000000 /* 128 MiB */
 static u64 __initdata dom0_mem = DOM0_MEM_DEFAULT;
index d5192b8b3c11f52a9df2b81ab6b4620cb70e8648..9aa65a8993dbf72fbfb54d7b5ecb2d269f7c9f39 100644 (file)
 #include <xsm/xsm.h>
 #include <xen/trace.h>
 
+#ifndef is_domain_direct_mapped
+# define is_domain_direct_mapped(d) ((void)(d), 0)
+#endif
+
 struct memop_args {
     /* INPUT */
     struct domain *domain;     /* Domain to be affected. */
@@ -122,7 +126,29 @@ static void populate_physmap(struct memop_args *a)
         }
         else
         {
-            page = alloc_domheap_pages(d, a->extent_order, a->memflags);
+            if ( is_domain_direct_mapped(d) )
+            {
+                mfn = gpfn;
+                if ( !mfn_valid(mfn) )
+                {
+                    gdprintk(XENLOG_INFO, "Invalid mfn %#"PRI_xen_pfn"\n",
+                             mfn);
+                    goto out;
+                }
+
+                page = mfn_to_page(mfn);
+                if ( !get_page(page, d) )
+                {
+                    gdprintk(XENLOG_INFO,
+                             "mfn %#"PRI_xen_pfn" doesn't belong to the"
+                             " domain\n", mfn);
+                    goto out;
+                }
+                put_page(page);
+            }
+            else
+                page = alloc_domheap_pages(d, a->extent_order, a->memflags);
+
             if ( unlikely(page == NULL) ) 
             {
                 if ( !opt_tmem || (a->extent_order != 0) )
@@ -270,6 +296,13 @@ static void decrease_reservation(struct memop_args *a)
              && p2m_pod_decrease_reservation(a->domain, gmfn, a->extent_order) )
             continue;
 
+        /* With the lack for iommu on some ARM platform, domain with DMA-capable
+         * device must retrieve the same pfn when the hypercall
+         * populate_physmap is called.
+         */
+        if ( is_domain_direct_mapped(a->domain) )
+            continue;
+
         for ( j = 0; j < (1 << a->extent_order); j++ )
             if ( !guest_remove_page(a->domain, gmfn + j) )
                 goto out;
index 28d39a0af47bdcc33606dfb0ff0ca44e70e4a885..e2202a6e340dea2b2a18f7cec513d8c04f756bfa 100644 (file)
@@ -86,6 +86,9 @@ enum domain_type {
 #define is_pv64_domain(d) (0)
 #endif
 
+extern int dom0_11_mapping;
+#define is_domain_direct_mapped(d) ((d) == dom0 && dom0_11_mapping)
+
 struct vtimer {
         struct vcpu *v;
         int irq;